import CryptoJS from 'crypto-js'

// TODO: refactor
// 秘钥必须为：8/16/32位
const AES_SECRET_KEY = 'N2I2NmU3NGZiZTU5MWJiNGJlOTg0N2Y0'

export default {
  // aes 加密
  encryption(cipher) {
    return CryptoJS.AES.encrypt(
      cipher,
      CryptoJS.enc.Utf8.parse(AES_SECRET_KEY),
      {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
      }
    )
  },
  // aes 解密
  decryption(cipher) {
    const decrypt = CryptoJS.AES.decrypt(
      cipher,
      CryptoJS.enc.Utf8.parse(AES_SECRET_KEY),
      {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
      }
    )
    return decrypt.toString(CryptoJS.enc.Utf8)
  },
}